package com.fr71.project.dm.controller;

import com.fr71.framework.aspectj.lang.annotation.Log;
import com.fr71.framework.aspectj.lang.enums.BusinessType;
import com.fr71.framework.web.controller.BaseController;
import com.fr71.framework.web.domain.AjaxResult;
import com.fr71.framework.web.page.TableDataInfo;
import com.fr71.common.utils.poi.ExcelUtil;
import com.fr71.project.dm.domain.PdPluginErr;
import com.fr71.project.dm.service.IPdPluginErrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 开发者：https://github.com/devzwy
 * 创建时间：2023-07-06
 * 类描述：异常统计Controller
 */
@RestController
@RequestMapping("/dm/err_total")
public class PdPluginErrController extends BaseController {
    
    @Autowired
    private IPdPluginErrService pdPluginErrService;

    /**
     * 查询异常统计列表
     */
    @PreAuthorize("@ss.hasPermi('dm:err_total:list')")
    @GetMapping("/list")
    public TableDataInfo list(PdPluginErr pdPluginErr) {
        startPage();
        List<PdPluginErr> list = pdPluginErrService.selectPdPluginErrList(pdPluginErr);
        return getDataTable(list);
    }

    /**
     * 导出异常统计列表
     */
    @PreAuthorize("@ss.hasPermi('dm:err_total:export')")
    @Log(title = "异常统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PdPluginErr pdPluginErr) {
        List<PdPluginErr> list = pdPluginErrService.selectPdPluginErrList(pdPluginErr);
        ExcelUtil<PdPluginErr> util = new ExcelUtil<PdPluginErr>(PdPluginErr.class);
        util.exportExcel(response, list, "异常统计数据");
    }

    /**
     * 获取异常统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('dm:err_total:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(pdPluginErrService.selectPdPluginErrById(id));
    }

    /**
     * 新增异常统计
     */
    @PreAuthorize("@ss.hasPermi('dm:err_total:add')")
    @Log(title = "异常统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PdPluginErr pdPluginErr) {
        return toAjax(pdPluginErrService.insertPdPluginErr(pdPluginErr));
    }

    /**
     * 修改异常统计
     */
    @PreAuthorize("@ss.hasPermi('dm:err_total:edit')")
    @Log(title = "异常统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PdPluginErr pdPluginErr) {
        return toAjax(pdPluginErrService.updatePdPluginErr(pdPluginErr));
    }

    /**
     * 删除异常统计
     */
    @PreAuthorize("@ss.hasPermi('dm:err_total:remove')")
    @Log(title = "异常统计", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(pdPluginErrService.deletePdPluginErrByIds(ids));
    }
}